package sz.szsmk.citizencard.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chenenyu.router.annotation.Route;
import com.google.gson.Gson;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.bean.response.IUserInfo;
import sz.szsmk.citizencard.ui.base.IBaseActivity;
import sz.szsmk.citizencard.ui.newversion.config.Constants;
import sz.szsmk.citizencard.util.ACache;
import sz.szsmk.citizencard.util.JumpUtils;
import sz.szsmk.citizencard.util.PubUtils;


/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/7/10 10:17
 * description:
 */
@Route("idsafe")
public class UserSafeActivity extends IBaseActivity implements View.OnClickListener {
    ImageView back;
    TextView settingTitle;
    TextView bjTv;
    RelativeLayout safeChangePhone;
    RelativeLayout safePsdAdmin;
    RelativeLayout safeQuestion;
    RelativeLayout safeBind;
    Button btn_logoff;
    TextView safePhone;
    private TextView title;
    private String userPhone;

    @Override
    protected int attachLayoutRes() {
        return R.layout.user_safe_activity;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initViews() {


        back = findViewById(R.id.back);
        back.setOnClickListener(this);
        settingTitle = findViewById(R.id.setting_title);
        bjTv = findViewById(R.id.bj_tv);
        safeChangePhone = findViewById(R.id.safe_change_phone);
        safeChangePhone.setOnClickListener(this);
        safePsdAdmin = findViewById(R.id.safe_psd_admin);
        safePsdAdmin.setOnClickListener(this);
        safeQuestion = findViewById(R.id.safe_question);
        safeQuestion.setOnClickListener(this);
        safeBind = findViewById(R.id.safe_bind);
        safeBind.setOnClickListener(this);
        btn_logoff = findViewById(R.id.btn_logoff);
        btn_logoff.setOnClickListener(this);
        safePhone = findViewById(R.id.safe_phone);


        title = findViewById(R.id.setting_title);
        TextView phone = findViewById(R.id.safe_phone);
        title.setText("账户与安全");
        String userinfo = ACache.get(this).getAsString("userinfo");
        IUserInfo mUserInfo = new Gson().fromJson(userinfo, IUserInfo.class);
        IUserInfo.UserExBean userEx = mUserInfo.getUserEx();
        if (userEx != null) {
            userPhone = userEx.getMobile();
            phone.setText(settingphone(userPhone));
        } else {
            JumpUtils.jump(this, "login", 0);
        }

    }

    @Override
    protected void updateViews() {

    }

    public static String settingphone(String phone) {
        String phone_s = phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
        return phone_s;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == R.id.back) {
            finish();
        } else if (id == R.id.safe_change_phone) {
            PubUtils.formatDate("变更手机号");
            Bundle bundle = new Bundle();
            bundle.putString("type", "modifyPhone");
            bundle.putString("userPhone", userPhone);
            bundle.putString("codeType", "4");
            JumpUtils.jumptoNatvie(this, "checkCode", 0, bundle);
//                JumpUtils.jump(this,"modifyPhone",0);
        } else if (id == R.id.safe_psd_admin) {
            PubUtils.formatDate("密码管理");
            JumpUtils.jump(this, "psdadmin", 0);
        } else if (id == R.id.safe_question) {
        } else if (id == R.id.safe_bind) {
            JumpUtils.jump(this, "bind", 0);
        } else if (id == R.id.btn_logoff) {
            JumpUtils.jump(this, Constants.LOGOFF, 0);
        }
    }

    @Override
    public void onClick(View v) {
        onViewClicked(v);
    }
}
